package org.example.designpatterns.singleton.demo4;


/**
 * @author Gong.Yang
 * 构造函数中加逻辑 解决破坏单例
 */
public class Singleton {
    private static final Singleton instance = new Singleton();

    private Singleton() {
        if(instance != null) {
            throw new RuntimeException("单例不允许破坏");
        }
    }

    public static Singleton getInstance() {
        return instance;
    }
}
